
module.exports = function ($scope, $state, $stateParams,$resource,$modal,iteminfo,$modalInstance,FileUploader, type, toaster) {
  console.log(iteminfo);
  $scope.item = iteminfo;
  $scope.type = type;
  var level = '';
  console.log($scope.type);
  if ($scope.type == '1') { // 区县初审
      level = '0';
  } else if ($scope.type == '0') { // 市级初审
      level = '1';
  } 
  $scope.rejectArr = [];
  // 公告类型
  $scope.typeFileArr = [
      {name:'王者类型',value:'1', id : '1'},
      {name:'青铜',value:'2', id : '2'},
      {name:'白银',value:'3', id : '3'},
      {name:'王者类型1',value:'4', id : '4'},
      {name:'青铜1',value:'5', id : '5'},
      {name:'白银1',value:'6', id : '6'},
      {name:'王者类型2',value:'7', id : '7'},
      {name:'青铜2',value:'8', id : '8'},
      {name:'白银2',value:'9', id : '9'}        
  ]
  // 详情
  $scope.getInfo = function(){
      $resource('/api/as/ggc/reviewPlanning/findInfo', {}, {}).save({'project_code':iteminfo.project_code}, function(res){			              
          if(res.errcode === 0 || res.errcode === 10003){
              console.log(res);
              $scope.a = res.data;
              if($scope.a.city_project=='0'){
                  $scope.a.city_project='区县项目'
              } else if($scope.a.city_project=='1'){
                  $scope.a.city_project='市本级项目'
              } 
              if($scope.a.project_build=='0'){
                  $scope.a.project_build='建设类'
              } else if($scope.a.project_build=='1'){
                  $scope.a.project_build='非建设类'
              }
              if($scope.a.project_level=='0'){
                  $scope.a.project_level='国家'
              } else if($scope.a.project_level=='1'){
                  $scope.a.project_level='省'
              } else if($scope.a.project_level=='2'){
                  $scope.a.project_level='市'
              } 
              $scope.getProjecttType($scope.a.project_type);
              // 材料
              console.log('材料');
              console.log(JSON.parse($scope.a.project_file));
              $scope.material = JSON.parse($scope.a.project_file);
              if($scope.material.aa){
                $scope.array1 = $scope.material.aa;
                console.log('array1');
                console.log($scope.array1);
              } else {
                $scope.array1 = undefined;
              }
              if($scope.material.bb){
                $scope.array2 = $scope.material.bb;
              } else {
                $scope.array2 = undefined;
              }
              $scope.array3 = $scope.material.cc;
              $scope.array4 = $scope.material.dd;
              $scope.array5 = $scope.material.ee;
              $scope.array6 = $scope.material.ff;
              $scope.array7 = $scope.material.gg;
              $scope.array8 = $scope.material.hh;
              $scope.array9 = $scope.material.ii;

          }else{
              alert(res.errmsg);
          }
      });
  }
  $scope.getInfo();
  $scope.array = [];
  $scope.newArr = [];
  // // 材料详情
  $scope.getCLInfo = function (){
      $resource('/api/ac/ggc/reviewCompanyRejectService/findCompanyRejectList', {}, {}).save({'project_code':iteminfo.project_code, 'type' : level}, function(res){			              
          if(res.errcode === 0 || res.errcode === 10003){
              console.log('材料详情');
              console.log(res);
              console.log(res.data);
              $scope.array = res.data;
          }else{
              alert(res.errmsg);
          }
      });
  }
  $scope.getCLInfo();
  $scope.getProjecttType = function(project_type){
      $scope.typeFileArr.forEach(element => {
        if(project_type == element.value){
          $scope.a.project_type = element.name;
        }
      });
  }
  $resource('/api/as/ggc/reviewGuide/findInfoTypeList', {}, {}).save({}, function(res){
      if(res.errcode === 0){                      
          // console.log(res);
          // console.log('上面是res');
          $scope.ntarr=[];
          for(var i =0;i<res.data.length;i++){
              $scope.ntarr.push({name:i,value:res.data[i].guide_type});
          }
          console.log($scope.ntarr);
      }else{
          alert(res.errmsg);
      }
  });
  // $scope.del=function(index){
  //     $scope.array.splice(index,1);
  //     $scope.a.project_file=$scope.array.join(',');
  // }
  // $scope.image = function(){
  //     var para = $state.get('app.imageupload');
  //     //设置上传文件夹，以自己业务命名
  //     angular.extend(para, {
  //       resolve : {  
  //         'dir' : function(){
  //           return 't1';
  //         }
  //       } 
  //     })
  //     console.log(para);
  //     var modalInstance = $modal.open(para);
  //     modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
  //       console.log('modal is opened');  
  //     });  
  //     modalInstance.result.then(function(result) {  
  //       console.log(result);  
  //       $scope.imagearr = JSON.stringify(result);
  //       // console.log(scope.imagearr);
  //       $scope.array = result;
  //       $scope.a.project_file=$scope.array;
  //       // $scope.a.project_file = array[0];
  //       // console.log(scope.info.img);
  //       // form.result['templete_lock_data_json'] = JSON.stringify(result.lock);
  //       // form.result['templete_check_data_json'] = result.unlock;

  //     }, function(reason) {  
  //       console.log(reason);// 点击空白区域，总会输出backdrop  
  //       // click，点击取消，则会暑促cancel  
  //       $log.info('Modal dismissed at: ' + new Date());  
  //     }); 
  // }; 
  // // 单条通过
  $scope.singlePass = function (str){
      console.log(str);
      var dic = {'img' : str, 'state' : '1'};
      $scope.rejectArr.push(dic);
      console.log('sei完得数组');
      console.log($scope.rejectArr);
      // 循环去掉重复元素
      if ($scope.rejectArr.length == '1'){
        console.log('一个不需要处理');
      } else {
          for (var i = 0; i < $scope.rejectArr.length - 1; i++){
            if ($scope.rejectArr[i + 1].img == $scope.rejectArr[i].img) {
              $scope.rejectArr.splice(i, 1);
            }
          }
          console.log('处理完得');
          console.log($scope.rejectArr);
      }
      var box1=document.getElementById(str);
      box1.style.display = '';
      console.log(box1);
      var box2=document.getElementById(str + '1');
      box2.style.display = 'none';
      toaster.success({title:"",body:'通过成功'});
  }  
  // 单条驳回
  $scope.singleReject = function (str){
      console.log(str);
      var box1=document.getElementById(str);
      box1.style.display = 'none';
      console.log(box1);
      var box2=document.getElementById(str + '1');
      box2.style.display = '';
      var modalInstance = $modal.open({
          template: require('../views/singel_back_reason.html'),
          controller: 'singel_back_reasons',
          size: 'xs',
          resolve: {
              str: function () {
                  return str;
              },
          }
      });
      modalInstance.result.then(function (showResult) {	
          console.log('带回来的驳回信息');
          console.log(showResult);
          $scope.rejectArr.push(showResult);
          console.log($scope.rejectArr);
          // 循环去掉重复元素
          if ($scope.rejectArr.length == '1'){
            console.log('一个不需要处理');
          } else {
              for (var i = 0; i < $scope.rejectArr.length - 1; i++){
                if ($scope.rejectArr[i + 1].img == $scope.rejectArr[i].img) {
                  $scope.rejectArr.splice(i, 1);
                }
              }
              console.log('处理完得');
              console.log($scope.rejectArr);
          }
      });  
  } 
  // 区县通过
  $scope.pass= function () {   
    if ($scope.type == '0'){
      $scope.flag = 'sjcstg';
        var modalInstance = $modal.open({
          template: require('../views/passInfo.html'),
          controller: 'passInfos',
          size: 'xs',
          resolve: {
              iteminfo: function () {
                  return $scope.item;
              },
              'flag': function () {
                  return 'sjcstg';
              },
          }
        });
        modalInstance.result.then(function (showResult) {	
          $modalInstance.close();
          $state.go('app.examines');
        });  
    } else if(type == '1') { //区县初审通过
        if(confirm('该项目是否通过初审？')){
            for (var i = 0; i < $scope.rejectArr.length; i++){
              if ($scope.rejectArr[i].state == '0'){
                alert('材料没有全部通过,不可通过该项目');
                return;
              }
            }
          $resource('/api/as/ggc/reviewDistrictTourism/updateByRecommend', {}, {}).save({'project_code':iteminfo.project_code}, function(res){			              
              if(res.errcode === 0 || res.errcode === 10003){
                  toaster.success({title:"",body:'通过成功'});
                  $modalInstance.close();
              }else{
                  toaster.error({title:"",body:res.errmsg});
              }
          });
          $resource('/api/as/ggc/reviewPlanning/insertReviewCompanyProjectLog', {}, {}).save({'project_code':iteminfo.project_code, 'recommend_type' : $scope.a.recommend_type, 'check_city' : $scope.a.check_city, 'check_state' : '1'}, function(res){			              
              if(res.errcode === 0 || res.errcode === 10003){
                  console.log(res);
              }else{
                  alert(res.errmsg);
              }
          });
          $resource('/api/ac/ggc/reviewCompanyRejectService/updateCompanyReject', {}, {}).save({'project_code' : iteminfo.project_code, 'type' : level}, function(res){			              
              if(res.errcode === 0 || res.errcode === 10003){
                  console.log(res);
              }else{
                  alert(res.errmsg);
              }
          });
        }	
    }
  }
  // 区县驳回
  $scope.againPass= function () {  
      if ($scope.type == '0') {
          $scope.flag = 'sjbh';
      }  else if ($scope.type == '1') {
          $scope.flag = 'qxbh';
      }
      var modalInstance = $modal.open({
          template: require('../views/reject_info.html'),
          controller: 'reject_infos',
          size: 'xs',
          resolve: {
              iteminfo: function () {
                  return $scope.item;
              },
              'flag': function () {
                  return $scope.flag;
              },
              'type': function () {
                  return $scope.type;
              },
              array: function () {
                  return $scope.rejectArr;
              },
          }
      });
      modalInstance.result.then(function (showResult) {	
        $modalInstance.close();
        $state.go('app.examines');
      });  	
  }
  // 区县淘汰
  $scope.eliminate= function () {  
    if ($scope.type == '0') {
        $scope.flag = 'sjtt';
    }  else if ($scope.type == '1') {
        $scope.flag = 'qxtt';
    }
      var modalInstance = $modal.open({
          template: require('../views/reject_info.html'),
          controller: 'reject_infos',
          size: 'xs',
          resolve: {
              iteminfo: function () {
                  return $scope.item;
              },
              'flag': function () {
                  return $scope.flag;
              },
              'type': function () {
                  return $scope.type;
              },
              array: function () {
                  return $scope.rejectArr;
              },
          }
      });
      modalInstance.result.then(function (showResult) {	
          $modalInstance.close();
          $state.go('app.examines');
      });  
  }

  $scope.close = function(){
      $modalInstance.close();
  }
};
